//
//  BCDebugUtils.m
//  Pod
//
//  Created by Basic on 2017/3/14.
//  Copyright © 2017年 naruto. All rights reserved.
//

#import "BCDebugUtils.h"

@interface BCDebugUtils()
@end

@implementation BCDebugUtils
#pragma mark - top page
+ (UIViewController *)topPage {
    UIViewController *vcRoot = [[[UIApplication sharedApplication] delegate] window].rootViewController;
    return [BCDebugUtils bcdebug_topViewController:vcRoot];
}
+ (UIViewController *)bcdebug_topViewController:(UIViewController *)viewController {
    if ([viewController isKindOfClass:[UINavigationController class]]) {
        return [BCDebugUtils bcdebug_topViewController:[(UINavigationController *)viewController topViewController]];
    }
    else if ([viewController isKindOfClass:[UITabBarController class]]) {
        return [BCDebugUtils bcdebug_topViewController:[(UITabBarController *)viewController selectedViewController]];
    }
    else if (viewController.presentedViewController) {
        return [BCDebugUtils bcdebug_topViewController:viewController.presentedViewController];
    }
    return  viewController;
}


#pragma mark - 判断是否越狱
+ (BOOL)deviceJailBroken {
    NSArray *jailbreak_tool_pathes = @[
                                       @"/Applications/Cydia.app",
                                       @"/Library/MobileSubstrate/MobileSubstrate.dylib",
                                       @"/bin/bash",
                                       @"/usr/sbin/sshd",
                                       @"/etc/apt"
                                       ];
    
    for (NSUInteger i = 0; i < jailbreak_tool_pathes.count; i++) {
        if ([[NSFileManager defaultManager] fileExistsAtPath:jailbreak_tool_pathes[i]]) {
            return YES;
        }
    }
    return NO;
}
@end
